package com.rbac.exception;

import org.springframework.http.HttpStatus;

import java.util.Objects;

public class BaseException extends RuntimeException {
    Integer code;
    String message;
    Object result;
    HttpStatus status;


    public BaseException(HttpStatus status) {
        super(status.getReasonPhrase());
        this.code = status.value();
        this.message = status.getReasonPhrase();
        this.status=status;
    }

    public BaseException(HttpStatus status, Object result) {
        this(status);
        this.result = result;
    }

    public BaseException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public BaseException(String message){
        this.message=message;
    }

    public BaseException(Integer code, String message, Object result) {
        this(code, message);
        this.result = result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        BaseException that = (BaseException) o;
        return Objects.equals(code, that.code) && Objects.equals(message, that.message) && Objects.equals(result, that.result) && status == that.status;
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, message, result, status);
    }

    public HttpStatus getHttpStatus() {
        return status;
    }

    public void setHttpStatus(HttpStatus status) {
        this.status = status;
    }
}